
var vm = new Vue({
    el : "#fzJobWriteInList",
    data : {
        record:{},
        sels:[],
        flyWeavs:[],
        jobStatus:[],
        table: null,
        jobCode: '',
        status: '',
        flyWeav: '',
    },
    init: function(){
        var _self = this;
        layui.use(['layer'], function(){
            layer = layui.layer;
        });
        this.$nextTick(function() {
            this.$http.post(host + "flyWeavController/selectFlyWeavs",{},{emulateJSON: true}).then(function(res){
                if(res.ok) {
                    _self.flyWeavs = res.body.flyWeavs;
                    layui.use('form', function() {
                        var form = layui.form;
                        window.setTimeout(function() {
                            form.render('select');

                            form.on("select(status)", function(obj) {
                                _self.status = obj.value;
                                _self.SelectLists();
                            });
                            form.on("select(flyWeav)", function(obj) {
                                _self.flyWeav = obj.value;
                                _self.SelectLists();
                            });
                        }, 300);
                    });
                }
            });
            _self.renderTable();
        });
    },
    methods: {
        SelectLists: function() {
            this.table.reload({page: {curr: 1}, where: {status: this.status, flyWeav: this.flyWeav, jobCode: this.jobCode}});
        },
        reset: function() {
            window.location.reload();
        },
        vueAlert: function(msg){
            layui.use(['form'], function(){
                layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        },
        renderTable: function(){
            var _self = this;
            layui.use(['form','table','laydate'], function(){
                var table = layui.table;
                var form = layui.form;

                _self.table = table.render({
                    id: 'fzJobListTable',
                    elem: '#fzJobListTable',
                    loading: true,
                    even: true,
                    width: 'full-20',
                    height: 'full-150',
                    cols: [[ //标题栏
                        {type:' numbers',title:'序号'},
                        {field: 'CODE', title: '作业工单号',minWidth: 160},
                        {field: 'NAME', title: '型体',minWidth: 180, align:'center' },
                        {field: 'COLORNAME', title: '颜色', minWidth: 120, align:'center'},
                        {field: 'SIZE_CODE', title: '尺码', minWidth: 100, align:'center'},
                        {field: 'FZJ', title: '飞织机机台', minWidth: 120, align:'center'},
                        {field: 'MATERIAL_OK', title: '状态', minWidth: 100, align:'center',
                            templet: function(data) {
                                if (data.MATERIAL_OK == 'Y') {
                                    return '已写RFID';
                                } else {
                                    return '未写RFID';
                                }
                            }},
                        {field: 'EXE_DATE_FROM', title: '飞织开工时间', minWidth: 160, align:'center'},
                        {field: 'EXE_DATE_TO', title: '飞织完工时间', minWidth: 160, align:'center'},
                        {field: 'ID', title: '操作', minWidth: 200, align:'center',
                            templet: function(data) {
                                if (data.MATERIAL_OK == 'Y') {
                                    return '<a class="layui-btn layui-btn-xs table_btn" lay-event="rewriter">重写RFID</a>';
                                } else {
                                    return '<a class="layui-btn layui-btn-xs table_btn" lay-event="rfid">写入RFID</a>';
                                }
                            }
                        }
                    ]],
                    method: "post",
                    url: host + "fzJobWriteIn/selectFlyWeavList",
                    page: true, //是否显示分页
                    limits: [10, 20, 50],
                    limit: 10 //每页默认显示的数量
                });

                //监听工具条
                table.on('tool(remakeReceiveFilter)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                    var row = obj.data; //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
                    if(layEvent == 'rfid') {
                        _self.updateJobStatus(row);
                    } else if(layEvent == 'rewriter') {
                        _self.writeRfid(row);
                    }
                });
            });
        },
        updateJobStatus: function(row) {
            this.writeRfid(row);
            this.$nextTick(function() {
                this.$http.post(host + "fzJobWriteIn/updateJobStatus",{jobCode: row.CODE},{emulateJSON: true}).then(function(res) {
                    if(res.ok) {
                        layer.msg("写入成功！");
                    } else {
                        layer.msg("写入失败");
                    }
                });
            });
        },
        writeRfid: function(row) {
            top.layer.open({
                type: 2,
                title: "写入RFID",
                shadeClose: true,
                shade: 0.6,
                area: ['300', '120'],
                fixed:true,
                content: 'http://localhost:28088/xdRfid/write?rfid=' + row.CODE,
                end:function(){
                }
            });
            window.setTimeout(function() {
                window.location.reload();
            }, 1000);
        }
    }
});